package com.sky.controller.user;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "套餐管理")
@RestController
@RequestMapping("/user/setmeal")
public class UserSetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 套餐列表查询
     * @param categoryId
     * @return
     */
    @ApiOperation("套餐列表")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmeal",key = "#a0")
    public Result<List<Setmeal>> list(@RequestParam Long categoryId){
        log.info("套餐列表：{}",categoryId);
        List<Setmeal> list = setmealService.getList(categoryId);

        return Result.success(list);
    }

    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @ApiOperation("根据套餐id查询菜品")
    @GetMapping("/dish/{id}")
    @Cacheable(cacheNames = "setmeal/dish",key = "#a0")
    public Result<List<DishItemVO>> dishItemList(@PathVariable Long id){
        log.info("根据套餐id查询菜品：{}",id);
        List<DishItemVO> list = setmealService.getDishItems(id);
        return Result.success(list);
    }


}
